
 ;
 ;              T O W E R S     O F     H A N O I  
 ;                       ( In   L I S P )           
 ;

 ( define TRANSFER-DISK
   ( lambda ( disk org dest temp )
     ( if ( > disk 0 )
       ( begin
         ( TRANSFER-DISK ( - disk 1 ) org temp dest )
         ( MOVE-DISK org dest )
         ( TRANSFER-DISK ( - disk 1 ) temp dest org )
        )
      )
    )
  )

 ( define MOVE-DISK
   ( lambda ( org dest )
     ( begin
       ( display "                    Move  " 'console )
       ( display org 'console )
       ( display "   To   " 'console )
       ( display dest 'console )
       ( newline 'console )
      )
    )
  )

 ( define HANOI
   ( begin
     ( set-video-mode! 3 )

     ( window-set-cursor! 'console 5 20 )
     ( display "  T O W E R S     O F     H A N O I  " 'console )
     ( window-set-cursor! 'console 9 20 )
     ( display "          ( In   L I S P )           " 'console )

     ( window-set-cursor! 'console 16 20 )
     ( display "     How Many Disks Do You Want ? " )
     ( define disk ( read ) )

     ( set-video-mode! 3 )

     ( window-set-cursor! 'console 0 15 )

     ( display "   Execute in following sequence : " 'console )
     ( newline 'console )
     ( newline 'console )
     ( TRANSFER-DISK disk 'Left 'Right 'Center )
    )
  )
